/*
 * Copyright (c) 2011  Cristian Constantin
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

package com.quizio.engine.model;

import com.quizio.engine.model.context.Editor;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.map.annotate.JsonView;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;

/**
 * @author Cristian Constantin
 * @since 10/16/11
 */
@Entity
@Table(name = "questions")
public class Question implements Serializable {

    private Long id;

    private String prompt;

    private Boolean singleChoice = Boolean.TRUE;

    private List<Option> options;

    @JsonView(Editor.class)
    private Integer weight = 1;

    @JsonIgnore
    private Quiz quiz;

    @Id
    @SequenceGenerator(name = "questions_pk_sequence", sequenceName = "questions_id_seq")
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "questions_pk_sequence")
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Column
    public String getPrompt() {
        return prompt;
    }

    public void setPrompt(String prompt) {
        this.prompt = prompt;
    }

    @Column(name = "single_choice")
    public Boolean getSingleChoice() {
        return singleChoice;
    }

    public void setSingleChoice(Boolean singleChoice) {
        this.singleChoice = singleChoice;
    }

    @OneToMany(mappedBy = "question")
    @Cascade(CascadeType.ALL)
    @OrderBy("id")
    public List<Option> getOptions() {
        return options;
    }

    public void setOptions(List<Option> options) {
        this.options = options;
    }

    @Column
    public Integer getWeight() {
        return weight;
    }

    public void setWeight(Integer weight) {
        this.weight = weight;
    }

    @ManyToOne
    public Quiz getQuiz() {
        return quiz;
    }

    public void setQuiz(Quiz quiz) {
        this.quiz = quiz;
    }
}
